package pers.llc.lambda.optional;

import java.util.Optional;

/**
 * Optional用法示例
 *
 * @author llc
 * @date: 2018/10/25 0025 22:07
 */
public class OptionalT {

    public static void main(String[] args) {
        User user = new User();
        user.setUserName("xxx");
        System.out.println(getName(user));
    }

    public static String getName(User u) {
        return Optional.ofNullable(u)
                .map(user -> user.getUserName())
                .orElse("Unknown");
    }

}
